package test5.lupeng.jf.com.teamdemo.adapter;

import android.content.Intent;
import android.media.Image;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import org.w3c.dom.Text;

import java.util.ArrayList;

import test5.lupeng.jf.com.teamdemo.R;
import test5.lupeng.jf.com.teamdemo.activitys.BlogDetailsActivity;
import test5.lupeng.jf.com.teamdemo.activitys.MyShareActivity;
import test5.lupeng.jf.com.teamdemo.bean.response.BlogResponse;
import test5.lupeng.jf.com.teamdemo.bean.response.ResponseMyshare;
import test5.lupeng.jf.com.teamdemo.untils.GlideCircleTransform;
import test5.lupeng.jf.com.teamdemo.untils.PostMethods;

/**
 * Created by Administrator on 2017/7/29.
 */

public class MyShareAdapter extends RecyclerView.Adapter{
     ArrayList<BlogResponse.ResultBean>  beans;

    public MyShareAdapter(ArrayList<BlogResponse.ResultBean> beans) {
        this.beans = beans;
    }
    class  ItemViewHolder extends RecyclerView.ViewHolder{
        TextView tv_title;
        TextView tv_look;
        TextView tv_date;
        ImageView iv_userhead;
        TextView  tv_authorName;
        public ItemViewHolder(View itemView) {
            super(itemView);
            tv_title = itemView.findViewById(R.id.tv_title);
            tv_look = itemView.findViewById(R.id.tv_look);
            tv_date = itemView.findViewById(R.id.tv_data);
            iv_userhead = itemView.findViewById(R.id.iv_authorPic);
            tv_authorName=itemView.findViewById(R.id.tv_authorName);
        }
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.myshare_item, parent, false);
        ItemViewHolder holder = new ItemViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        BlogResponse.ResultBean bean = beans.get(position);
        final ItemViewHolder holder1= (ItemViewHolder) holder;
        holder1.tv_title.setText(bean.getTitle());
        holder1.tv_look.setText(bean.getLikeSize()+"");
        holder1.tv_date.setText(PostMethods.times(bean.getTimestamp()));
        Glide.with(holder1.itemView.getContext())
                .load(bean.getAuthor()
                .getHeadProtrait())
                .centerCrop()
                .transform(new GlideCircleTransform(holder1.itemView.getContext()))
                .into(holder1.iv_userhead);
        holder1.tv_authorName.setText(bean.getAuthor().getUsername());

        holder1.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent  intent=new Intent(holder1.itemView.getContext(), BlogDetailsActivity.class);
                intent.putExtra("blog",beans.get(position));
                holder1.itemView.getContext().startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return beans.size();
    }
}
